#include<stdio.h>
#include<vector>
#include <iostream>
#include <map>
using namespace std;
/**
 * Definition for singly-linked list.
 **/
struct ListNode 
{
    int val;
    ListNode *next;
    ListNode(int x) : val(x), next(NULL) {}
};
 
class Solution {
public:
    ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) {
        int jw = 0;
        ListNode *p1= l1, *p2= l2,*ans=NULL,*head;
        
        while (p1 != NULL&&p2!=NULL)
        {
            if (ans == NULL)
            {
                ans = new ListNode(0);
                head = ans;
            }
            else
            {
                ans->next = new ListNode(0);
                ans = ans->next;
            }
            ans->val = p1->val + p2->val + jw;
            if (ans->val / 10)jw = 1;
            else jw = 0;
            ans->val %= 10;
            p1 = p1->next;
            p2 = p2->next;
        }
        if (p2 != NULL)p1 = p2;
        while (p1 != NULL)
        {
            if (ans == NULL)
            {
                ans = new ListNode(0);
                head = ans;
            }
            else
            {

                ans->next = new ListNode(0);
                ans = ans->next;
            }
            ans->val = p1->val + jw;
            if (ans->val / 10)jw = 1;
            else jw = 0;
            ans->val %= 10;
            ans->next = NULL;
            p1 = p1->next;
        }
        if (jw)
        {
            if (ans == NULL)
            {
                ans = new ListNode(0);
                head = ans;
            }
            else
            {

                ans->next = new ListNode(0);
                ans = ans->next;
            }
            ans->val = jw;
            ans->next = NULL;
        }
        return head;
    }
};
int main()
{

}

